<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目所属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">项目状态：</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">委托方</label>
                        <div class="layui-input-block">
                            <input type="text" name="lian_unit" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">

    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>

    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });


        setSouTableExport('项目经营汇总表');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_engin_jinghui_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                xmselect_dan('chanid', res.data.chanid, res.data.is_chanid, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(res.data.is_state == key){
                        state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                    }else {
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }

                }
                $("#state").html(state_str);

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type:'numbers',title:'序号',fixed:'left',totalRowText: '合计'}
                ,{field:'name',title:'项目名称',fixed:'left',templet: function(d){
                        return '<span class="colorlan" onclick="openPage(\'../engin/show.php?id='+d.id+'\')">'+d.name+'</span>';
                    }}
                ,{field: 'chanid_name', title: '项目所属单位'}
                ,{field: 'number', title: '项目编号'}
                ,{field: 'state_name', title: '项目状态'}
                ,{field: 'lian_unit', title: '委托方'}

                ,{field:'shibumoney',title:'施工合同金额含变更(元)',totalRow: true,align:'right',event: 'contract_shi',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.shibumoney)+'</span>';
                    }}
                ,{field:'shijiemoney',title:'施工合同结算金额(元)',totalRow: true,align:'right',event: 'contract_shi_jie',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.shijiemoney)+'</span>';
                    }}
                ,{field: 'lei_piaokai', title: '累计开票金额(元)',totalRow: true,align:'right',event: 'piao_kai',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.lei_piaokai)+'</span>';
                    }}
                ,{field: 'incomeenginfee', title: '累计收款金额(元)A',totalRow: true,align:'right',event: 'income_engin',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.incomeenginfee)+'</span>';
                    }}
                ,{field: 'gonghuifee', title: '其中工程回款金额(元)',totalRow: true,align:'right',event: 'income_engin_gong',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.gonghuifee)+'</span>';
                    }}
                ,{field: 'weilaifee', title: '其中委托方来款金额(元)',totalRow: true,align:'right',event: 'income_engin_wei',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.weilaifee)+'</span>';
                    }}


                ,{field:'caimoney',title:'采购合同金额含变更(元)',totalRow: true,align:'right',event: 'contract_cai',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.caimoney)+'</span>';
                    }}
                ,{field:'caijiemoney',title:'采购合同结算金额(元)',totalRow: true,align:'right',event: 'contract_cai_jie',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.caijiemoney)+'</span>';
                    }}
                ,{field: 'piaoshoufee', title: '累计收票金额(元)',totalRow: true,align:'right',event: 'piao_shou',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.piaoshoufee)+'</span>';
                    }}


                ,{field: 'payenginfee', title: '累计付款(元) B',totalRow: true,align:'right',event: 'payment_engin',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.payenginfee)+'</span>';
                    }}
                ,{field: 'neikoufee', title: '累计扣款(元) C',totalRow: true,align:'right',event: 'tai_neiming',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.neikoufee)+'</span>';
                    }}
                ,{field: 'payment_xiangfu', title: '累计结算支付(元) D',totalRow: true,align:'right',event: 'payment_xiangfu',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.payment_xiangfu)+'</span>';
                    }}
                ,{field: 'balance', title: '项目余额(元) A-B-C-D',totalRow: true,align:'right',templet: function(d){
                        return '<span>'+parseFormatNum(d.balance)+'</span>';
                    }}
                ,{field: 'leikoudai', title: '累计待扣(元)',totalRow: true,align:'right',event: 'engin_kou',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.leikoudai)+'</span>';
                    }}
                ,{field: 'shengjiefee', title: '项目可用余额(元)',totalRow: true,align:'right',templet: function(d){
                        return '<span>'+parseFormatNum(d.shengjiefee)+'</span>';
                    }}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });

        table.on('tool(datalist)',function (obj) {
            var data = obj.data;
            if(obj.event === 'contract_shi'){
                openNavPage('施工合同信息','contract_shi/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'contract_shi_jie'){
                openNavPage('施工合同结算信息','contract_shi_jie/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'piao_kai'){
                openNavPage('开票信息','piao_kai/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'income_engin'){
                openNavPage('项目收款信息','income_engin/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'income_engin_gong'){
                openNavPage('项目工程回款信息','income_engin/index.php?enginid='+data.id+'&status=1&gongkuan=1');
            }
            if(obj.event === 'income_engin_wei'){
                openNavPage('项目委托方来款信息','income_engin/index.php?enginid='+data.id+'&status=1&gongkuan=2');
            }


            if(obj.event === 'contract_cai'){
                openNavPage('采购合同信息','contract_cai/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'contract_cai_jie'){
                openNavPage('采购合同结算信息','contract_cai_jie/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'piao_shou'){
                openNavPage('收票信息','piao_shou/index.php?enginid='+data.id+'&status=1');
            }


            if(obj.event === 'payment_engin'){
                openNavPage('项目付款信息','payment_engin/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'tai_neiming'){
                openNavPage('扣款登记明细信息','tai_neiming/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'payment_xiangfu'){
                openNavPage('累计结算支付','payment_xiangfu/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'engin_kou'){
                openNavPage('应扣费用表','engin_kou/index.php?enginid='+data.id+'&status=1');
            }


        });

        listTableSearch(form, table);
    });



    function auth_but_func_guan(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('../engin/zong.php?enginid='+trData.id);
    }

</script>
</body>
</html>
